package com.system.demo.mapper.auth;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.system.demo.entity.auth.SystemRole;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SystemRoleMapper extends BaseMapper<SystemRole> {

    @Select("SELECT COALESCE(MAX(role_id), 0) AS max_role_id FROM system_role")
    Integer getMaxRoleId();


    @Select("SELECT role_id FROM system_role WHERE is_available = 1")
    List<Integer> getAvailableRoleIds();


    @Update("UPDATE system_role SET is_available = #{isAvailable} WHERE role_id = #{roleId}")
    int updateIsAvailable(@Param("roleId") Integer roleId, @Param("isAvailable") Integer isAvailable);

    @Select("SELECT uid FROM user_role WHERE role_id = #{roleId}")
    List<String> getUidByRoleId(@Param("roleId") Integer roleId);

}
